//
//  SXTAFNetworkingClient.m
//  SXT
//
//  Created by 赵金鹏 on 16/8/16.
//  Copyright © 2016年 赵金鹏. All rights reserved.
//

#import "SXTAFNetworkingClient.h"

@implementation SXTAFNetworkingClient

+ (instancetype)shareClient{
    static SXTAFNetworkingClient *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[SXTAFNetworkingClient alloc]initWithBaseURL:[NSURL URLWithString:@"http://123.57.141.249:8080/beautalk/"]];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    });
    return manager;
}

+ (void)POSTRequest:(NSString *)url
              param:(NSDictionary *)param
          isSuccess:(requestSuccessBlock)returnSuccess
            isError:(requestErrorBlock)returnError{
    
    
    [[SXTAFNetworkingClient shareClient] POST:url
       parameters:param
         progress:nil
          success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
              if (returnSuccess) {
                  returnSuccess(responseObject);
              }
              
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (returnError) {
            returnError(error);
        }
    }];
    
    
}

+ (void)GETRequest:(NSString *)url
             param:(NSDictionary *)param
         isSuccess:(requestSuccessBlock)returnSuccess
           isError:(requestErrorBlock)returnError{
    [[SXTAFNetworkingClient shareClient] GET:url
       parameters:param
         progress:nil
          success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
              
              if (returnSuccess) {
                  returnSuccess(responseObject);
              }
              
          } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              
              if (returnError) {
                  returnError(error);
              }
          }];
}


@end
